﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NewFormatProject.Infrastructure.Atrributes;
using NewFormatProject.Infrastructure.Dto.Requests.Objects;
using NewFormatProject.Server.Instances;
using NewFormatProject.Server.Instances.Extends.Requests;
using NewFormatProject.Server.Interfaces;
using System.Threading.Tasks;

namespace NewFormatProject.Api.Admin.Controllers
{
    [Authorize]
    [CheckLogin]
    public class UserController:BaseController
    {
        private readonly IUserServer _userServer;
        public UserController(IUserServer userServer)
        {
            _userServer = userServer;
        }
        /// <summary>
        /// 获取用户详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Detail(int id)
        {
            return Ok(await _userServer.Detail(id));
        }
        /// <summary>
        /// 以分页的形式返回用户列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Pagination(int page,int limit,string key)
        {
            return Ok(await _userServer.Pagination(page,limit,key));
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("添加用户")]
        public async Task<IActionResult> Add(RequestSysUsersDto dto)
        {
            return Ok(await _userServer.Add(dto));
        }
        /// <summary>
        /// 更新用户和头像图片
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("更新用户和头像图片")]
        public async Task<IActionResult> UpdateWithImage([FromForm]RequestSysUsersDto dto)
        {
            return Ok(await _userServer.UpdateWithImage(dto));
        }
        /// <summary>
        /// 更新用户不更新头像图片
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("更新用户不更新头像图片")]
        public async Task<IActionResult> UpdateWithoutImage(RequestSysUsersDto dto)
        {
            return Ok(await _userServer.UpdateWithoutImage(dto));
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [ActionLog("删除用户")]
        public async Task<IActionResult> Delete(RequestSysUsersDto dto)
        {
            return Ok(await _userServer.Delete(dto));
        }

    }
}
